<template>
    <div class="Myinvitation">
        <div class="titel"><h1>我的邀请</h1></div>
        <div class="modification">
            <div class="img">
                <img src="../../assets/qrcode_localhost.png" alt="" />
                <p>邀请用户扫码注册</p>
            </div>
            <div class="text">
                <div><span>复制链接邀请用户注册</span></div>
                <div>
                    <el-input
                        v-model="input"
                        readonly="readonly"
                        id="copyValERC20"
                    ></el-input>
                    <el-button
                        class="copyBtn"
                        type="info"
                        data-clipboard-target="#copyValERC20"
                        @click="copy"
                        >复制链接</el-button
                    >
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import ClipboardJS from "clipboard";
export default {
    data() {
        return {
            input: "http://localhost:8080/#/insuranceSystem/MyInvit",
        };
    },
    methods: {
        copy() {
            // 创建一个新的ClipboardJS('.copyBtn'),()内为按钮的class
            var copyBtn = new ClipboardJS(".copyBtn");
            copyBtn.on("success", (e) => {
                this.$message({
                    message: "已成功复制",
                    type: "success",
                    duration: 700,
                });
                copyBtn.destroy(); // 释放内存
            });
            copyBtn.on("error", (e) => {
                this.$message({
                    message: "复制失败",
                    type: "error",
                    duration: 500,
                });
                copyBtn.destroy();
            });
        },
    },
};
</script>

<style lang="scss">
.Myinvitation {
    .titel {
        line-height: 40px;
        background: rgba(185, 169, 169, 0.911);
        h1 {
            margin-left: 20px;
            color: rgb(255, 255, 255);
        }
    }
    .modification {
        padding: 0px 200px 0px 200px;
        margin-top: 20px;
        background: white;
        height: 500px;
        display: flex;
        align-items: center;
        justify-content: space-around;
        .img {
            text-align: center;
            img {
                width: 200px;
                margin-bottom: 20px;
            }
        }
        .text {
            .el-input {
                margin-top: 20px;
                width: 200px;
                margin-right: 20px;
            }
        }
    }
}
</style>